package com.suian.spring.controller;


import com.suian.spring.Application;
import com.suian.spring.bean.Playsingleton;
import com.suian.spring.bean.Plaything;
import com.suian.spring.redis.LockTest;
import com.suian.spring.redis.RedisDistributedLock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @Autowired
    private Plaything plaything;
    @Autowired
    private Playsingleton playsingleton;

    @Autowired
    private LockTest lockTest;

    @RequestMapping("/lock1")
    public void testRedis() {
        lockTest.Lock1();
    }
    @RequestMapping("/lock2")
    public void testRedis2() {
        lockTest.Lock2();
    }

    @RequestMapping("/lock3")
    public void testRedis3() throws InterruptedException {
        lockTest.lockRedission();
    }
    @RequestMapping("/lock4")
    public void testRedis4() throws InterruptedException {
        lockTest.lockRedission2();
    }
    @RequestMapping("/test")
    public String testHelloWorld() {

        System.out.println(playsingleton);

        return "hello spring";
    }

    @RequestMapping("/testScope")
    public void testScope() {
        System.out.println(plaything);
    }

    @RequestMapping("/testException")
    public void testException() throws Exception {
        throw new Exception("自定义异常");
    }

    @RequestMapping("/testRuntimeException")
    public void testRuntimeException() throws Exception {
        throw new RuntimeException("自定义异常");
    }
}
